/* GUI CONVERTED from apvotax.i (converter v1.76) Tue Mar 18 16:13:34 2003 */
/* apvotax.i - AP VOUCHER INVENTORY COST TAX ACCUMULATION               */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.7.1.9 $                                             */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 8.6           CREATED: 10/13/97   BY: *H0ZP* Samir Bavkar  */
/* REVISION: 8.6     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan    */
/* REVISION: 8.6E    LAST MODIFIED: 07/23/98   BY: *L03K* Jeff Wootton  */
/* Pre-86E commented code removed, view in archive revision 1.6         */
/* REVISION: 9.0     LAST MODIFIED: 03/10/99   BY: *M0B3* Michael Amaladhas */
/* REVISION: 9.0     LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan        */
/* REVISION: 9.0     LAST MODIFIED: 04/20/99   BY: *M0BG* Jeff Wootton      */
/* REVISION: 9.1     LAST MODIFIED: 11/01/99   BY: *N053* Jeff Wootton      */
/* REVISION: 9.1     LAST MODIFIED: 08/11/00   BY: *N0KK* jyn               */
/* Revision: 1.7.1.7 BY: Katie Hilbert  DATE: 04/01/01 ECO: *P002* */
/* Revision: 1.7.1.8 BY: Patrick Rowan DATE: 05/24/02  ECO: *P018* */
/* $Revision: 1.7.1.9 $            BY: Tiziana Giustozzi   DATE: 01/13/03 ECO: *P0MX* */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*! USED BY apvocsu1.p AND apvomta3.p                                   */

   for each tx2d_det
         where tx2d_ref     = tax_ref
         and tx2d_nbr     = tax_nbr
         and tx2d_tr_type = rcpt_tr_type
         and tx2d_line    = pvo_line
         and tx2d_tottax  <> 0 /* TOTAL TAXABLE IS NOT ZERO */
         no-lock:
   

      /* WHEN A RATE VARIANCE WILL RESULT IN AN AVG COST CHANGE, WE */
      /* DO NOT INCLUDE EDITED RECEIPT TAXES COPIED TO THE VOUCHER  */
      /* WHEN CALCULATING THE TAX PORTION OF THE RATE VARIANCE.  THE*/
      /* EDITED TAX AMOUNT REMAINS CONSTANT WHEN COPIED TO THE NEXT */
      /* STAGE IN THE CYCLE.  EDITED TAXES ARE NOT TO BE INCLUDED IN*/
      /* THE TAX PORTION OF A RATE VARIANCE CALCULATION DONE DURING */
      /* VOUCHER, REGARDLESS OF WHEN TAXES ARE ACCRUED.             */

      for first tx2_mstr no-lock where
         tx2_tax_code = tx2d_tax_code:
      end.

      /* HAVE TAXES BEEN EDITED? */

      if tx2d_edited = yes and
        (tx2d_rcpt_tax_point = yes or
        (tx2d_rcpt_tax_point = no and
         pod_consignment          and
         tx2_usage_tax_point = yes))
      then next.



      /* TAX INCLUDED = NO */
      if not tx2d_tax_in
      then do:

         /* CALCULATE PORTION OF NON-RECOVERABLE TAX   */
         /* WHICH NEEDS TO BE ADDED TO THE VARIANCE.   */
         assign
            taxamt_this_tx2d = (totl_amt
               * (tx2d_cur_tax_amt - tx2d_cur_recov_amt)
               / tx2d_totamt)
            /* VARIANCE AMOUNT */
            /* MULTIPLIED BY TOTAL TAX MINUS RECOVERABLE TAX, */
            /* DIVIDED BY TOTAL TAXABLE. */
            taxamt = taxamt + taxamt_this_tx2d

            tax_on_vph_price = tax_on_vph_price
                             + (vph_inv_cost
                             * (tx2d_cur_tax_amt - tx2d_cur_recov_amt)
                             / tx2d_totamt).

         /*ACCRUE AT VOUCHER AS LONG AS RCPT_TAX_POINT IS NO AND*/
         /*WE ARE NOT DEALING WITH A CONSIGNED LINE ITEM.       */
         /*IF THE LINE IS CONSIGNED, THEN CHECK THE USAGE_TAX_POINT*/
         /*TO SEE IF IT IS SET TO NO.                              */
         if tx2d_rcpt_tax_point = no and
            (pod_consignment = no        /* NON-CONSIGNED LINE ITEM */
                     or
            (pod_consignment and tx2_usage_tax_point  = no))
            then
         do:
            /* PO RECEIPT NON-RECOVERABLE TAX */
            tax_on_receipt = tax_on_receipt
            /* ADD VOUCHER NON-RECOVERABLE TAX (BASE-CURR) */
            + (tx2d_tax_amt - tx2d_recov_amt).

            if rcpt_tr_type = "22" then
               tax_on_receipt = tax_on_receipt
            /* SUBTRACT VARIANCE NON-RECOVERABLE TAX */
                              - taxamt_this_tx2d.
         end.

      end. /* TAX INCLUDED = NO */
      else do: /* TAX INCLUDED = YES */
         /* AMOUNT INCLUDES                               */
         /* RECOVERABLE AND NON-RECOVERABLE TAX.          */

         /* CALCULATE PORTION OF RECOVERABLE TAX          */
         /* WHICH NEEDS TO BE SUBTRACTED FROM VARIANCE.   */
         assign
            taxamt_this_tx2d = (totl_amt
            * (- tx2d_cur_recov_amt)
            / (tx2d_totamt /*+ tx2d_cur_tax_amt*/))          /*modify by tony*/
            /* VARIANCE AMOUNT */
            /* MULTIPLIED BY MINUS RECOVERABLE TAX, */
            /* DIVIDED BY TOTAL TAXABLE + INCLUDED TAX */
            taxamt = taxamt + taxamt_this_tx2d



            tax_on_vph_price = tax_on_vph_price
            + (vph_inv_cost * (- tx2d_cur_recov_amt)
            / (tx2d_totamt  /*+ tx2d_cur_tax_amt*/))  /*modify by tony*/

			     curr_cost_taxamt = curr_cost_taxamt
         + (totl_amt
         * (- tx2d_cur_recov_amt)
         / tx2d_totamt).


         /*ACCRUE AT VOUCHER AS LONG AS RCPT_TAX_POINT IS NO AND*/
         /*WE ARE NOT DEALING WITH A CONSIGNED LINE ITEM.       */
         /*IF THE LINE IS CONSIGNED, THEN CHECK THE USAGE_TAX_POINT*/
         /*TO SEE IF IT IS SET TO NO.                              */
         if tx2d_rcpt_tax_point = no and
            (pod_consignment = no        /* NON-CONSIGNED LINE ITEM */
                     or
            (pod_consignment and tx2_usage_tax_point  = no))
         then
         do:
            /* PO RECEIPT NON-RECOVERABLE TAX */
            tax_on_receipt = tax_on_receipt
            /* ADD VOUCHER NON-RECOVERABLE TAX (BASE-CURR) */
            + (tx2d_tax_amt - tx2d_recov_amt).

            if rcpt_tr_type = "22" then
            tax_on_receipt = tax_on_receipt
            /* SUBTRACT VARIANCE NON-RECOVERABLE TAX */
            - (totl_amt
            * (tx2d_cur_tax_amt - tx2d_cur_recov_amt)
            / tx2d_totamt).
         end.

      end. /* TAX INCLUDED = YES */
   end. /* FOR EACH TAX DETAIL */
